package com.wyf.video

import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.google.gson.Gson
import com.wyf.video.global.Const
import com.wyf.video.model.Bt
import jaydenxiao.com.expandabletextview.ExpandableTextView
import kotlinx.android.synthetic.main.activity_detail.*
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk25.coroutines.onClick
import android.content.Context.CLIPBOARD_SERVICE
import android.text.ClipboardManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import org.jetbrains.anko.toast


class DetailActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detail)
        receive()
        initEvent()
    }

    private fun initEvent() {
        detail_back.onClick {
            finish()
        }
    }

    fun receive() {
        var film = Gson().fromJson(intent.getStringExtra(Const.PASS_BT), Bt::class.java)
        show(film)
    }

    private fun show(film: Bt) {

        Glide.with(this).load(film.poster).diskCacheStrategy(DiskCacheStrategy.ALL).into(detail_poster)
        detail_name.text = film.name
        detail_puttime.text = film.putTime
        detail_resolution.text = film.resolution
        detail_type.text = film.type[0]
        detail_language.text = "语言："+film.language[0]

        var str = ""
        for (i in film.actor){
            str+=i.trim()+"\n"
            if (film.actor.indexOf(i)==2){
                break
            }
        }
        detail_actor.text = "主演：\n"+str
        detail_intorduce.text = film.introduce

        if(film.hd.count()>0){
            detail_btn_copy.text = film.hd.get(0).name
        }else{
            detail_hd.visibility = View.GONE
        }
        if (film.bd.count()>0){
            detail_btn_copy_bd.text = film.bd.get(0).name
        }else{
            detail_bd.visibility = View.GONE
        }

        detail_btn_copy.onClick {
            val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            // 将文本内容放到系统剪贴板里。
            cm.setText(film.hd[0].link)
            toast("已复制到粘贴板中")

        }
        detail_btn_copy_bd.onClick {
            val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            // 将文本内容放到系统剪贴板里。
            cm.setText(film.bd[0].link)
            toast("已复制到粘贴板中")
        }
    }
}

